<?php
require_once dirname(__FILE__) . '/includes/common.inc.php';
require_once dirname(__FILE__) . "/database/$database/database.inc.php";

header('Content-Type: text/plain');

global $myManager;

try {
  $hostname = HOST_NAME;
  $username = USER_NAME1;
  $password = PASSWORD1;
  $dbname = DATABASE_NAME1;
  $myPdo = new PDO ('mysql:host=' . $hostname, $username, $password);
  $myPdo->exec('USE ' . $dbname);
  $myPdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

} catch (PDOException $e) {
  echo $e->getMessage ();
}

try {
  $sqls = array();
  
  $sql = "select moc.e_oid as id, moc.date from ns_myordercancel as moc";
  $stmt = $myPdo->prepare($sql);
  $stmt->execute();
  $i = 0; $results = array();
  while ($i < $stmt->rowCount()) {
    $tmp = $stmt->fetch(PDO::FETCH_OBJ);
	$tmp->date = ($tmp->date != 0) ? SimpleDate::fromStamp($tmp->date) : NULL;
	$results[] = $tmp;
    $i++;
  }
  
  foreach ($results as &$r) {
    $sql = 'update ns_myordercancel as moc set moc.date=' . (($r->date) ? SimpleDate::toStamp(SimpleDate::create($r->date->year, $r->date->month, $r->date->date)) : 0) . ' where moc.e_oid = ' . $r->id;
	$sqls[] = $sql;
  }
  
  
  foreach ($sqls as &$sq) {
    MiscUtils::dump($sq);
    $myPdo->exec($sq);
  }
  
} catch (PDOException $e) {
  echo $e->getMessage();
}
?>